﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SVAP
{
    public partial class VideoForm : Form
    {
        bool isDuration;         //标志位，表示还未显示视频的持续时间
        internal bool isConfigure;        //标志位，表示是否已经配置，若无配置，则无法开始分析
        internal bool videoStart;  //标志位，表示视频分析是否已经开始

        int time = 0;  //计时时间

        internal ConfigAlgorithmForm caf = null;

        public VideoForm()
        {
            InitializeComponent();

            //初始化，置标志位
            isDuration = false;    
            isConfigure = false;
            videoStart = false;

            //进度标签清空
            label_Tips.Visible = false;
        }

        //关闭视频分析窗口
        //private void btn_exit_Click(object sender, EventArgs e)
        //{
        //    this.Close();         
        //}

        //计时器
        private void timer_duration_Tick(object sender, EventArgs e)
        {
            try
            {

                //获取视频的持续时间
                if (this.axWindowsMediaPlayer_main.currentMedia.duration != 0 && isDuration == false)
                {
                    this.label_main.Text += this.axWindowsMediaPlayer_main.currentMedia.durationString;
                    this.axWindowsMediaPlayer_main.Ctlcontrols.stop();
                    isDuration = true;
                    this.timer_duration.Interval = 1000;    //修改计时器的间隔为1000毫秒
                }

                //在进度标签中显示内容
                if (videoStart == true)
                {
                    time++;
                    //label_Tips.Text += " " + (time / 60).ToString() + " 分 " + " " + (time % 60).ToString() + " 秒"; //显示已用时间
                    label_Tips.Text = "正在分析...  已用时 " + (time / 60).ToString() + " 分 " + " " + (time % 60).ToString() + " 秒"; //显示已用时间;
                }
            }
            catch { }
        }

        //配置
        private void btn_config_Click(object sender, EventArgs e)
        {
            if (caf == null || caf.IsDisposed)
            {
                caf = new ConfigAlgorithmForm();
            }

            caf.Owner = this;
            caf.Show();
            caf.Focus();
        }

        //开始分析
        private void btn_analysis_Click(object sender, EventArgs e)
        {
            if (isConfigure == true)
            {
                videoStart = true;          //置标志位为开始
                label_Tips.Visible = true;  //显示进度标签
                
            }
            else
                MessageBox.Show("请先配置算法和输出结果，再开始分析。");
        }

        //保存分析结果
        private void btn_saveResult_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "txt文档(*.txt)|*.txt";

            if (sfd.ShowDialog() == DialogResult.OK)
                richTextBox_showResult.SaveFile(sfd.FileName);
        }

        //清除分析结果
        private void btn_wipe_Click(object sender, EventArgs e)
        {
            richTextBox_showResult.Clear();
        }
    }
}
